#!/bin/bash

#------------------------------------------------------------------------------
#Filename:	74839-patch.sh
#Version:	1.1
#Date:	        2013/08/05
#Author:	yuanhui.shi
#Email:	        yuanhui.shi@cs2c.com.cn
#Summary:	02.01系统核心功能-06基础命令行工具-22diff工具-03制作patch文件
#Notes:	        通过diff工具，制作patch
#Copyright:	China Standard Software Co.,Ltd.
#History:
#	        Version 1.0,2013/08/05
#	        -The first one
#	        Version 1.1,2013/09/09
#	        -Modify the script to satisfy the shell standard
#------------------------------------------------------------------------------


PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

source ../../lib/Echo.sh

function CleanData ()
{
  rm -rf ./file/hello.patch
  sed -i 's/ world//g' ./file/hello_old.c

  EchoInfo "74839-patch.sh执行完毕"
}

trap "CleanData" EXIT

diff -Naru ./file/hello_old.c ./file/hello_new.c >./file/hello.patch

EchoInfo "通过patch命令，对现有的hello_old.c进行更新"
patch  -p0 <./file/hello.patch &>/dev/null 

test "`LANG=C diff -s ./file/hello_old.c ./file/hello_new.c`" == "Files ./file/hello_old.c and ./file/hello_new.c are identical" 
EchoResult "文件patch制作成功了"


